package org.example;

public class Test2 {
    //leetcode 75 颜色分类 https://leetcode.cn/problems/sort-colors/
    public void sortColors(int[] nums) {
        int n = nums.length;
        int left = -1,right = n,i = 0;
        while(i < right) {
            if(nums[i] < 1) swap(nums,++left,i++);
            else if(nums[i] == 1) i++;
            else swap(nums,--right,i);
        }
    }

    private void swap(int[] nums, int x, int y) {
        int tmp = nums[x];
        nums[x] = nums[y];
        nums[y] = tmp;
    }

    public static void main(String[] args) {
        int[] arr = {2,0,1};
        Test2 test2 = new Test2();
        test2.sortColors(arr);
        System.out.println(788);
    }
}
